package com.itheima.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

import java.util.Arrays;

public class MyAspect {


    @Pointcut("execution(void com.itheima.dao.BookDao.*())")
    public void pt(){}

    @Before("pt()")
    public void before(JoinPoint joinPoint) {

        Object[] args = joinPoint.getArgs();
        System.out.println(Arrays.toString(args));

        System.out.println("before advice...");
    }

    @After("pt()")
    public void after() {
        System.out.println("after advice...");
    }

    @Around("pt()")
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("around before advice...");

        Object[] args = joinPoint.getArgs();

        args[0] = 666;

        joinPoint.proceed(args);

        System.out.println("around after advice...");
    }

    @AfterReturning("pt()")
    public void afterReturning() {
        System.out.println("afterReturning advice...");
    }

    @AfterThrowing("pt()")
    public void afterThrowing() {
        System.out.println("afterThrowing advice...");
    }

}
